package core

import (
	"context"
	"log"
	"time"

	"github.com/redis/go-redis/v9"
)

var Redis = initRedis()

func initRedis() *redis.Client {
	opt, err := redis.ParseURL("redis://localhost:6379")
	if err != nil {
		log.Fatal("initRedis redis.ParseURL err: ", err)
	}
	opt.PoolSize = 100
	client := redis.NewClient(opt)
	ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
	defer cancel()
	_, err = client.Ping(ctx).Result()
	if err != nil {
		log.Fatal("initRedis client.Ping err: ", err)
	}
	return client
}
